package com.yunji.base.engine.calculate;

public class FileSizeCalculate {

    private static final String FILE_SIZE_B = "B";
    private static final String FILE_SIZE_KB = "KB";
    private static final String FILE_SIZE_MB = "MB";
    private static final String FILE_SIZE_GB = "GB";

    public static String getFileSize(Long size) {
        if (size == null) {return null;}
        if (size < 1024) {
            return size + FILE_SIZE_B;
        } else if (size < 1024 * 1024) {
            return size / 1024 + FILE_SIZE_KB;
        } else if (size < 1024 * 1024 * 1024) {
            return size /1024 /1024 + FILE_SIZE_MB;
        } else {
            return size + FILE_SIZE_GB;
        }
    }

}
